#include <stdio.h>
#include <stdlib.h>
void assert (int id, unsigned char check, unsigned long long clock) {
  static unsigned char failed[3] = {0,0,0};
  if (! check) {
    if (id == 0) { if (! failed[id]) { printf("ASSERTION FAILURE: steering works at time %lli\n", clock); failed[id] = 1; } }
    else if (id == 1) { if (! failed[id]) { printf("ASSERTION FAILURE: target is closer than 1800 to actual' at time %lli\n", clock); failed[id] = 1; } }
    else if (id == 2) { if (! failed[id]) { printf("ASSERTION FAILURE: target is closer than 1800 to actual at time %lli\n", clock); failed[id] = 1; } }
  }
}
void cover  (int id, unsigned char check, unsigned long long clock) {
  static unsigned char covered[0] = {};
  if (check) {
    
  }
}
#include "fakearduino.h"
int newestRight = 0;
int newestLeft = 0;
int compass = 850;

void loop(void);
int targetHeading = 1800;
int actualHeading = 0;
int steering = 0;
int bearing = 0;


static unsigned long long __global_clock = 0;



static unsigned char __v7 = 0;  /* atom_unit_test.steering control left.right.s */
static unsigned char __v6 = 0;  /* atom_unit_test.steering control left.left.s */
static unsigned char __v5 = 0;  /* atom_unit_test.throtle */
static signed short __v4 = 0;  /* atom_unit_test.rightSum */
static signed short __v3 = 0;  /* atom_unit_test.leftSum */
static signed short __v2 = 0;  /* atom_unit_test.dodgeSteering */
static unsigned char __v1 = 0;  /* atom_unit_test.moving */
static unsigned char __v0 = 0;  /* atom_unit_test.dodging */

static signed short __a4[5] = {0,0,0,0,0};  /* atom_unit_test.rightDistanceMeasurements */
static signed short __a3[5] = {0,0,0,0,0};  /* atom_unit_test.leftDistanceMeasurements */
static unsigned char __a2[32] = {105,105,105,90,90,90,75,75,90,90,105,90,75,75,90,105,105,105,105,105,90,75,75,75,75,105,75,105,105,75,75,0};  /* atom_unit_test.steerings */
static signed short __a1[31] = {800,900,1001,900,1001,1101,1001,999,0,3500,51,151,51,49,3549,49,0,3400,3549,3551,51,3590,500,0,3500,2500,3350,3301,3250,3300,0};  /* atom_unit_test.actuals */
static signed short __a0[31] = {1000,1000,1000,1000,1000,1000,1000,1000,0,50,50,50,50,50,50,50,0,3550,3550,3550,3550,3550,3550,0,1500,1500,1500,1500,1500,1500,0};  /* atom_unit_test.targets */

/* atom_unit_test */
static void __r0(void) {
  unsigned char __0 = 1;
  unsigned long long __1 = __global_clock;
  signed short __2 = __a1[__1] /* atom_unit_test.actuals */ ;
  signed short __3 = __a0[__1] /* atom_unit_test.targets */ ;
  if (__0) {
    printf("clock: %i\n", __1);
  }
  compass = __2;
  targetHeading = __3;
}

/* atom_unit_test.read compass */
static void __r1(void) {
  unsigned char __0 = 1;
  signed short __1 = COMPASS;
  if (__0) {
  }
  actualHeading = __1;
}

/* atom_unit_test.steering control left */
static void __r2(void) {
  unsigned char __0 = 1;
  unsigned char __1 = __v6 /* atom_unit_test.steering control left.left.s */ ;
  unsigned char __2 = __v7 /* atom_unit_test.steering control left.right.s */ ;
  unsigned char __3 = 75;
  unsigned char __4 = 90;
  unsigned char __5 = __2 ? __3 : __4;
  unsigned char __6 = 105;
  unsigned char __7 = __1 ? __5 : __6;
  signed short __8 = 1800;
  signed short __9 = actualHeading;
  signed short __10 = targetHeading;
  signed short __11 = __9 - __10;
  unsigned char __12 = __8 < __11;
  signed short __13 = 3600;
  signed short __14 = __10 + __13;
  signed short __15 = __12 ? __14 : __10;
  signed short __16 = __10 - __9;
  unsigned char __17 = __8 < __16;
  signed short __18 = __9 + __13;
  signed short __19 = __17 ? __18 : __9;
  signed short __20 = __15 - __19;
  if (__0) {
    printf("target': %i\n", __15);
    printf("actual': %i\n", __19);
    printf("difference: %i\n", __20);
    printf("steering: %i\n", __7);
    printf("-------------------------------------------\n");
  }
  steering = __7;
}

/* atom_unit_test.steering control left.left */
static void __r3(void) {
  unsigned char __0 = 1;
  unsigned char __1 = __v6 /* atom_unit_test.steering control left.left.s */ ;
  signed short __2 = 1800;
  signed short __3 = targetHeading;
  signed short __4 = actualHeading;
  signed short __5 = __3 - __4;
  unsigned char __6 = __2 < __5;
  signed short __7 = 3600;
  signed short __8 = __4 + __7;
  signed short __9 = __6 ? __8 : __4;
  signed short __10 = __4 - __3;
  unsigned char __11 = __2 < __10;
  signed short __12 = __3 + __7;
  signed short __13 = __11 ? __12 : __3;
  signed short __14 = 100;
  signed short __15 = __13 - __14;
  unsigned char __16 = __13 < __15;
  signed short __17 = __16 ? __13 : __15;
  unsigned char __18 = __9 < __17;
  unsigned char __19 = ! __18;
  unsigned char __20 = __15 < __13;
  signed short __21 = __20 ? __13 : __15;
  unsigned char __22 = __21 < __9;
  unsigned char __23 = ! __22;
  unsigned char __24 = __1 && __19 && __23;
  unsigned char __25 = ! __24;
  unsigned char __26 = __25 && __23;
  unsigned char __27 = ! __26;
  if (__0) {
  }
  __v6 /* atom_unit_test.steering control left.left.s */ = __27;
}

/* atom_unit_test.steering control left.right */
static void __r4(void) {
  unsigned char __0 = 1;
  unsigned char __1 = __v7 /* atom_unit_test.steering control left.right.s */ ;
  signed short __2 = 1800;
  signed short __3 = targetHeading;
  signed short __4 = actualHeading;
  signed short __5 = __3 - __4;
  unsigned char __6 = __2 < __5;
  signed short __7 = 3600;
  signed short __8 = __4 + __7;
  signed short __9 = __6 ? __8 : __4;
  signed short __10 = __4 - __3;
  unsigned char __11 = __2 < __10;
  signed short __12 = __3 + __7;
  signed short __13 = __11 ? __12 : __3;
  signed short __14 = 100;
  signed short __15 = __13 + __14;
  unsigned char __16 = __15 < __13;
  signed short __17 = __16 ? __15 : __13;
  unsigned char __18 = __9 < __17;
  unsigned char __19 = ! __18;
  unsigned char __20 = __13 < __15;
  signed short __21 = __20 ? __15 : __13;
  unsigned char __22 = __21 < __9;
  unsigned char __23 = ! __22;
  unsigned char __24 = __1 && __19 && __23;
  unsigned char __25 = ! __24;
  unsigned char __26 = __25 && __23;
  unsigned char __27 = ! __26;
  if (__0) {
  }
  __v7 /* atom_unit_test.steering control left.right.s */ = __27;
}

/* atom_unit_test.distance measurements */
static void __r7(void) {
  unsigned char __0 = __v0 /* atom_unit_test.dodging */ ;
  signed short __1 = newestRight;
  signed short __2 = 0;
  signed short __3 = __a4[__2] /* atom_unit_test.rightDistanceMeasurements */ ;
  signed short __4 = __1 + __3;
  signed short __5 = 1;
  signed short __6 = __a4[__5] /* atom_unit_test.rightDistanceMeasurements */ ;
  signed short __7 = __4 + __6;
  signed short __8 = 2;
  signed short __9 = __a4[__8] /* atom_unit_test.rightDistanceMeasurements */ ;
  signed short __10 = __7 + __9;
  signed short __11 = 3;
  signed short __12 = __a4[__11] /* atom_unit_test.rightDistanceMeasurements */ ;
  signed short __13 = __10 + __12;
  signed short __14 = 4;
  signed short __15 = __a4[__14] /* atom_unit_test.rightDistanceMeasurements */ ;
  signed short __16 = __13 + __15;
  signed short __17 = __v4 /* atom_unit_test.rightSum */ ;
  signed short __18 = __0 ? __16 : __17;
  signed short __19 = newestLeft;
  signed short __20 = __a3[__2] /* atom_unit_test.leftDistanceMeasurements */ ;
  signed short __21 = __19 + __20;
  signed short __22 = __a3[__5] /* atom_unit_test.leftDistanceMeasurements */ ;
  signed short __23 = __21 + __22;
  signed short __24 = __a3[__8] /* atom_unit_test.leftDistanceMeasurements */ ;
  signed short __25 = __23 + __24;
  signed short __26 = __a3[__11] /* atom_unit_test.leftDistanceMeasurements */ ;
  signed short __27 = __25 + __26;
  signed short __28 = __a3[__14] /* atom_unit_test.leftDistanceMeasurements */ ;
  signed short __29 = __27 + __28;
  signed short __30 = __v3 /* atom_unit_test.leftSum */ ;
  signed short __31 = __0 ? __29 : __30;
  signed short __32 = __0 ? __12 : __15;
  signed short __33 = __0 ? __9 : __12;
  signed short __34 = __0 ? __6 : __9;
  signed short __35 = __0 ? __3 : __6;
  signed short __36 = __0 ? __1 : __3;
  signed short __37 = __0 ? __26 : __28;
  signed short __38 = __0 ? __24 : __26;
  signed short __39 = __0 ? __22 : __24;
  signed short __40 = __0 ? __20 : __22;
  signed short __41 = __0 ? __19 : __20;
  if (__0) {
  }
  __v4 /* atom_unit_test.rightSum */ = __18;
  __v3 /* atom_unit_test.leftSum */ = __31;
  __a4[__14] /* atom_unit_test.rightDistanceMeasurements */ = __32;
  __a4[__11] /* atom_unit_test.rightDistanceMeasurements */ = __33;
  __a4[__8] /* atom_unit_test.rightDistanceMeasurements */ = __34;
  __a4[__5] /* atom_unit_test.rightDistanceMeasurements */ = __35;
  __a4[__2] /* atom_unit_test.rightDistanceMeasurements */ = __36;
  __a3[__14] /* atom_unit_test.leftDistanceMeasurements */ = __37;
  __a3[__11] /* atom_unit_test.leftDistanceMeasurements */ = __38;
  __a3[__8] /* atom_unit_test.leftDistanceMeasurements */ = __39;
  __a3[__5] /* atom_unit_test.leftDistanceMeasurements */ = __40;
  __a3[__2] /* atom_unit_test.leftDistanceMeasurements */ = __41;
}

/* atom_unit_test.drive */
static void __r5(void) {
  unsigned char __0 = 1;
  unsigned char __1 = steering;
  unsigned char __2 = __v5 /* atom_unit_test.throtle */ ;
  if (__0) {
    STEERING(__1); THROTTLE(__2);
  }
}

/* atom_unit_test.calculate dodge */
static void __r6(void) {
  unsigned char __0 = __v0 /* atom_unit_test.dodging */ ;
  signed short __1 = 1200;
  signed short __2 = __v3 /* atom_unit_test.leftSum */ ;
  unsigned char __3 = __1 < __2;
  unsigned char __4 = ! __3;
  signed short __5 = __v4 /* atom_unit_test.rightSum */ ;
  unsigned char __6 = __1 < __5;
  unsigned char __7 = ! __6;
  unsigned char __8 = __4 && __7;
  unsigned char __9 = ! __8;
  unsigned char __10 = __0 && __9;
  signed short __11 = __2 - __5;
  signed short __12 = __v2 /* atom_unit_test.dodgeSteering */ ;
  signed short __13 = __10 ? __11 : __12;
  if (__10) {
  }
  __v2 /* atom_unit_test.dodgeSteering */ = __13;
}


static void __assertion_checks(void) {
  unsigned char __0 = 1;
  unsigned char __1 = steering;
  unsigned long long __2 = __global_clock;
  unsigned char __3 = __a2[__2] /* atom_unit_test.steerings */ ;
  unsigned char __4 = __1 == __3;
  unsigned char __5 = ! __4;
  unsigned long long __6 = 1ULL;
  unsigned long long __7 = __2 - __6;
  unsigned char __8 = __a2[__7] /* atom_unit_test.steerings */ ;
  unsigned char __9 = __1 == __8;
  unsigned char __10 = ! __9;
  unsigned char __11 = __5 && __10;
  unsigned char __12 = ! __11;
  signed short __13 = 1800;
  signed short __14 = targetHeading;
  signed short __15 = actualHeading;
  signed short __16 = __14 - __15;
  unsigned char __17 = __13 < __16;
  signed short __18 = 3600;
  signed short __19 = __15 + __18;
  signed short __20 = __17 ? __19 : __15;
  signed short __21 = __15 - __14;
  unsigned char __22 = __13 < __21;
  signed short __23 = __14 + __18;
  signed short __24 = __22 ? __23 : __14;
  signed short __25 = __20 - __24;
  unsigned char __26 = __13 < __25;
  unsigned char __27 = ! __26;
  signed short __28 = __24 - __20;
  unsigned char __29 = __13 < __28;
  unsigned char __30 = ! __29;
  if (__0) assert(0, __12, __global_clock);
  if (__0) assert(1, __27, __global_clock);
  if (__0) assert(2, __30, __global_clock);
}


void atom_unit_test(void) {
  {
    static unsigned char __scheduling_clock = 0;
    if (__scheduling_clock == 0) {
      __assertion_checks(); __r0();  /* atom_unit_test */
      __assertion_checks(); __r1();  /* atom_unit_test.read compass */
      __assertion_checks(); __r2();  /* atom_unit_test.steering control left */
      __assertion_checks(); __r3();  /* atom_unit_test.steering control left.left */
      __assertion_checks(); __r4();  /* atom_unit_test.steering control left.right */
      __assertion_checks(); __r7();  /* atom_unit_test.distance measurements */
      __scheduling_clock = 0;
    }
    else {
      __scheduling_clock = __scheduling_clock - 1;
    }
  }
  {
    static unsigned char __scheduling_clock = 0;
    if (__scheduling_clock == 0) {
      __assertion_checks(); __r5();  /* atom_unit_test.drive */
      __scheduling_clock = 4;
    }
    else {
      __scheduling_clock = __scheduling_clock - 1;
    }
  }
  {
    static unsigned char __scheduling_clock = 0;
    if (__scheduling_clock == 0) {
      __assertion_checks(); __r6();  /* atom_unit_test.calculate dodge */
      __scheduling_clock = 1;
    }
    else {
      __scheduling_clock = __scheduling_clock - 1;
    }
  }

  __global_clock = __global_clock + 1;
}

int main() {
  int loop;
  srand(0);

  for (loop = 0; loop < 32; loop++) {
    atom_unit_test();

  }

  return 0;
}

